<%@ page import="com.luntan.school.dao.PostsDao" %>
<%@ page import="com.luntan.school.service.Posts" %>
<%@ page import="java.util.List" %>
<%@ page import="com.luntan.school.dao.impl.PostsDaoImpl" %><%--
  Created by IntelliJ IDEA.
  User: 舒俊容
  Date: 2023/12/19
  Time: 11:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>



<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>论坛首页</title>
  <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.15.4/css/all.min.css">
  <link rel="stylesheet" href="css/index.css">
  <link rel="stylesheet" href="css/bootstrap.css">

  <style>
    body{
      background-image: url("./img/school.jpg");
      background-size: cover;
      background-repeat: no-repeat;
    }
  </style>
</head>
<body>

<header class="header container">
  <jsp:include page="commons/header.jsp"></jsp:include>
</header>
<nav class="nav container">
  <ul class="nav-links">
    <jsp:include page="commons/headerlist.jsp"></jsp:include>
  </ul>
</nav>
<div class="parttwo">
  <div class="sidebar1">
    <ul class="sidebar-links1">
      <jsp:include page="commons/side-bar.jsp"></jsp:include>
    </ul>

  </div>
  <div class="content container">
    <%
      System.out.println(request.getRemoteAddr());

      PostsDao postsDao = new PostsDaoImpl();
      // 获取URL参数
      String category = request.getParameter("category");
      String tag = request.getParameter("tag");
      List<Posts> postsList;
      if(category != null ) {
        postsList = postsDao.getPostsByCategory(Integer.parseInt(category));
      } else if( tag != null ) {
        postsList = postsDao.getPostsByTag(Integer.parseInt(tag));
      }
      else {
        postsList = postsDao.getStickPosts(6); // 获取首页帖子列表
      }
      for(Posts posts: postsList) {
    %>
    <div class="card">

      <img src="img/<%=posts.getImg()%>" alt="">
      <div class="title"><a href="postdetail.jsp?id=<%=posts.getId()%>"><%=posts.getTitle()%></a></div>
      <div class="meta">
        <span>作者：<%=posts.getEditor().getName()%></span>
        <span><%=posts.getCommentNum()%>评论</span>
        <span><%=posts.getPubDateInterval()%></span>
      </div>


    </div>
    <%}%>

  </div>
  <jsp:include page="commons/hot-posts.jsp"></jsp:include>

</div>


</body>

</html>
